package com.cheng.student.controller.servlet;

import com.cheng.student.beans.StudentFull;
import com.cheng.student.service.StudentServiceImpl;
import com.cheng.student.utils.GetJsonUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "GetStudentFullServlet", value = "/teacher/GetStudentFullServlet")
public class GetStudentFullServlet
        extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        String name = request.getParameter("name");
        String examNumber = request.getParameter("examNumber");
        //校验
        if (name == null||examNumber == null
                ||"".equals(name)||"".equals(examNumber))
        {
            response.getWriter().write("信息有误");
            return;
        }
        //通过

        StudentServiceImpl studentService = new StudentServiceImpl();

        StudentFull studentFull = studentService.getStudentFull(name, examNumber);

        if (studentFull == null)
        {
            response.getWriter().write("查无此人");
            return;
        }
        String json = GetJsonUtil.getJson(studentFull);
        response.getWriter().write(json);


    }
}
